﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;

namespace Noke.Common.DatabaseAccess
{
    public class DatabaseAccessConfig
    {
        private DatabaseAccessConfig() { }
        private static DatabaseAccessConfig _instance = null;
        public static DatabaseAccessConfig GetInstance()
        {
            if (_instance == null)
            {
                _instance = new DatabaseAccessConfig();
                _instance.SetDatabaseConnectionType();
            }
            return _instance;
        }

        private string prefix = "@";
        public string Prefix
        {
            get { return prefix; }
        }

        private DatabaseConnectionType dbConnectionType = DatabaseConnectionType.SQLSERVER;
        public DatabaseConnectionType DbConnectionType
        {
            get { return dbConnectionType; }
        }

        private void SetDatabaseConnectionType()
        {
            int _DbConnectionType = Convert.ToInt32(ConfigurationManager.AppSettings["DatabaseConnectionType"]);
            dbConnectionType = DatabaseConnectionType.Null;
            prefix = "@";
            switch (_DbConnectionType)
            {
                case (int)DatabaseConnectionType.SQLSERVER:
                    dbConnectionType = DatabaseConnectionType.SQLSERVER;
                    prefix = "@";
                    break;
                case (int)DatabaseConnectionType.ORACLE:
                    dbConnectionType = DatabaseConnectionType.ORACLE;
                    prefix = ":";
                    break;
                case (int)DatabaseConnectionType.MYSQL:
                    dbConnectionType = DatabaseConnectionType.MYSQL;
                    prefix = "?";
                    break;
            }
        }
    }

    public enum DatabaseConnectionType
    {
        Null = -1,
        SQLSERVER = 0,
        ORACLE = 1,
        MYSQL = 2,
    }
}
